package main.java.middle;

/**
 * @Author: 郑国荣
 * @Date: 2023-08-17-16:01
 * @Description:
 */
public class convertNString {
//   1 1 2 2 3 4  4 6  5 8
    public static String convert(String s,int numRows){
        int n = s.length();
        if ( numRows>=n || n<2) return s;
        StringBuilder[] mat = new StringBuilder[numRows];
        for (int i = 0; i < numRows; i++) {
            mat[i] = new StringBuilder();
        }
        for (int i = 0,x=0,t=numRows*2-2; i < n; i++) {
            mat[x].append(s.charAt(i));
            if (i%t<numRows-1) x++;
            else x--;
        }
        StringBuilder sb = new StringBuilder();
        for (StringBuilder row : mat) {
            sb.append(row);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s ="abcdefg";
        int row = 3;
        System.out.println(convert(s, row));
    }
}
